<?php

namespace My\Controller;

use My\Controller\MyController;

/**
 * 我的学习-评测记录
 */
class MyAbilityController extends MyController {

    //评测列表
    public function abilityCheckList() {
        $iUserId = $this->iUserId;
        $iPageNo = $this->getParam('page_no', 1, 'int+');
        $arrWhere['ac.read_auth'] = array('exp', '& 1');
        $arrWhere['ac.user_id'] = $iUserId;
        $arrField = array(
            'ac.ability_check_id,ac.user_id,ac.check_level,ac.create_time',
            'c.company_name',
            'u.real_name, u.phone',
            'ca.cate_name'
        );
        
        $arrJoin = array(
            'qy_company as c USING(company_id)',
            'qy_user as u ON u.user_id=ac.user_id',
            'left join qy_category_all as ca ON ca.cate_id = ac.cate_id AND ca.type = 1'
        );

        $objModel = M();
        $iCheckCount = $objModel->table('qy_ability_check ac')->field($arrField)->join($arrJoin)->where($arrWhere)->count();
        $iPageSize = 10;
        $arrCheckList = $objModel->table('qy_ability_check ac')->field($arrField)->join($arrJoin)->where($arrWhere)->order('ac.ability_check_id DESC')->page($iPageNo)->limit($iPageSize)->select();
        if(!empty($arrCheckList)){
            foreach($arrCheckList as &$val){
                $val['check_level_name'] = abilityLevelName($val['check_level']);
            }
        }
        $this->returnList($arrCheckList, $iPageNo, $iPageSize, $iCheckCount);
    }
    
    /**
     * 个人能力报告信息
     */
    public function abilityReportInfo() {
        $iAbilityCheckId = $this->getParam('ability_check_id', '', 'int+', true);
        $iUserId = $this->iUserId;
        
        $AbilityCheckModel = new \Common\Model\AbilityCheckModel();
        $retrunList = $AbilityCheckModel->abilityCheckReportInfo($iAbilityCheckId, 1, $iUserId);
        
        $this->returnList($retrunList);
    }

    /**
     * 能力评测删除(用户)
     */
    public function abilityDeleteForUser() {
        $iAbilityCheckId = $this->getParam('ability_check_id', 0, 'int+', TRUE);
        $iUserId = $this->iUserId;
        $arrWhere['ability_check_id'] = $iAbilityCheckId;
        $arrWhere['read_auth'] = array('exp', '& 1');
        $arrWhere['user_id'] = $iUserId;
        $res = M('AbilityCheck')->where($arrWhere)->setField('read_auth', array('exp', 'read_auth - 1'));
        if ($res) {
            $this->success();
        } else {
            $this->error();
        }
    }

}
